﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Linyb.Linq.QueryExtension
{
    public interface IFieldPredicate : IComparePredicate
    {
        object Value { get; set; }
    }

    public class FieldPredicate<T> : ComparePredicate, IFieldPredicate
        where T : class
    {
        public object Value { get; set; }

        public override string GetSql(SqlConditionUtil util, IList<object> parameters)
        {
            string columnName = GetColumnName(typeof(T), util, PropertyName);
            if (Value == null)
            {
                return string.Format("({0} IS {1}NULL)", columnName, Not ? "NOT " : string.Empty);
            }

            string parameterName = $"@{parameters.Count()}";
            parameters.Add(Value);
            return GetConditionString(columnName, parameterName);
        }
    }
}
